<template>
  <div class="mod-fii__fiicourse">
    <el-form :inline="true" :model="dataForm" @keyup.enter="getDataList()">
      <el-form-item>
        <el-input v-model="dataForm.title" placeholder="名称" clearable></el-input>
      </el-form-item>
      <el-form-item>
        <el-button @click="getDataList()">{{ $t("query") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button type="info" @click="exportHandle()">{{ $t("export") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiicourse:save')" type="primary" @click="addOrUpdateHandle()">{{ $t("add") }}</el-button>
      </el-form-item>
      <el-form-item>
        <el-button v-if="hasPermission('fii:fiicourse:delete')" type="danger" @click="deleteHandle()">{{ $t("deleteBatch") }}</el-button>
      </el-form-item>
    </el-form>
    <el-table v-loading="dataListLoading" :data="dataList" border @selection-change="dataListSelectionChangeHandle" style="width: 100%">
      <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
      <el-table-column prop="orderNo" label="排序" header-align="center" align="center" width="120px"></el-table-column>
      <el-table-column prop="categoryName" label="课程分类" header-align="center" align="center" width="120px"></el-table-column>
      <el-table-column prop="title" label="课程名称" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="pic" label="封面图" header-align="center" align="center" width="80px">
        <template v-slot="scope">
          <img v-if="scope.row.pic" :src="scope.row.pic" class="avatar" style="width: 50px; height: 50px" />
        </template>
      </el-table-column>
      <el-table-column prop="period" label="适用学段" header-align="center" align="center" width="120px"></el-table-column>
      <el-table-column prop="scene" label="适用场景" header-align="center" align="center" width="120px"></el-table-column>
      <el-table-column prop="topic" label="专题" header-align="center" align="center" width="200px"></el-table-column>
<!--      <el-table-column prop="theme" label="主题" header-align="center" align="center" width="200px"></el-table-column>-->
      <el-table-column prop="tools" label="配套教具" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="introduction" label="简介" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="price" label="价格" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="status" label="发布状态 " header-align="center" align="center" width="200px">
        <template v-slot="scope">
          <template v-for="(itemDict, i) in dict.status" :key="i" :hehe="111">
            <el-tag v-if="scope.row.status === parseInt(itemDict.code)" size="small">{{ itemDict.name }}</el-tag>
          </template>
        </template>
      </el-table-column>
      <!--
      <el-table-column prop="type" label="课程类型" header-align="center" align="center" width="200px">
        <template v-slot="scope">
          <template v-for="(itemDict, i) in dict.type" :key="i" :hehe="111">
            <el-tag v-if="scope.row.type === parseInt(itemDict.code)" size="small">{{ itemDict.name }}</el-tag>
          </template>
        </template>
      </el-table-column>
      -->
      <el-table-column prop="tuijian" label="推荐" header-align="center" align="center" width="60px">
        <template v-slot="scope">
          <label v-if="scope.row.tuijian">是</label>
          <label v-else>否</label>
        </template>
      </el-table-column>
      <!--      <el-table-column prop="createAt" label="创建时间" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="creator" label="创建人" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="updateAt" label="修改时间" header-align="center" align="center" width="200px"></el-table-column>
      <el-table-column prop="updator" label="修改人" header-align="center" align="center" width="200px"></el-table-column>-->
      <el-table-column :label="$t('handle')" fixed="right" header-align="center" align="center" width="170">
        <template v-slot="scope">
          <el-button v-if="hasPermission('fii:fiicourse:update')" type="text" size="small" @click="tuijianHandle(scope.row.id)">推荐</el-button>
          <el-button v-if="hasPermission('fii:fiicourse:update')" type="text" size="small" @click="addOrUpdateHandle(scope.row.id)">{{ $t("update") }}</el-button>
          <el-button v-if="hasPermission('fii:fiicourse:delete')" type="text" size="small" @click="deleteHandle(scope.row.id)">{{ $t("delete") }}</el-button>
          <el-button v-if="hasPermission('fii:fiicourse:update')" type="text" size="small" @click="editClassHour(scope.row.id)">课时</el-button>
          <el-button v-if="hasPermission('fii:fiicourse:update')" type="text" size="small" @click="editCourseFile(scope.row.id)">教案</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination :current-page="page" :page-sizes="[10, 20, 50, 100]" :page-size="limit" :total="total" layout="total, sizes, prev, pager, next, jumper" @size-change="pageSizeChangeHandle" @current-change="pageCurrentChangeHandle"> </el-pagination>
    <!-- 弹窗, 新增 / 修改 -->
    <add-or-update v-if="addOrUpdateVisible" ref="addOrUpdate" @refreshDataList="getDataList"></add-or-update>
    <!-- 字典类型数据 -->
    <el-drawer :title="focusDictTypeTitle" v-model="dictTypeListVisible" :size="800" close-on-press-escape="false" custom-class="rr-drawer"> <DictTypeList :courseId="courseId"></DictTypeList></el-drawer>
    <!-- 教案 -->
    <el-drawer :title="courseFileTitle" v-model="courseFileVisible" :size="800" close-on-press-escape="false" custom-class="rr-drawer"> <CourseFile :courseId="courseId"></CourseFile></el-drawer>
  </div>
</template>

<script lang="ts">
import useView from "@/hooks/useView";
import { defineComponent, nextTick, reactive, toRefs } from "vue";
import AddOrUpdate from "./fiicourse-add-or-update.vue";
import DictTypeList from "./fiiclasshour.vue";
import CourseFile from "./fiiclasshourfile.vue";
import Template from "@/views/devtools/template.vue";
import baseService from "@/service/baseService";
import ui from "@/utils/ui";
export default defineComponent({
  components: {
    AddOrUpdate,
    DictTypeList,
    CourseFile
  },
  setup() {
    const state = reactive({
      focusDictTypeTitle: "添加课时",
      dictTypeListVisible: false,
      courseFileTitle: "管理教案",
      courseFileVisible: false,

      courseId: "",
      dict: {
        status: baseService.strDict("0:未发布,1:已发布"),
        type: baseService.strDict("1:平台课程,2:集团定制,3:自定义"),
        categoryId: baseService.urlDict("/fii/fiicoursecategory/dict/list?parentId=0")
      },
      getDataListURL: "/fii/fiicourse/page",
      getDataListIsPage: true,
      exportURL: "/fii/fiicourse/export",
      deleteURL: "/fii/fiicourse",
      deleteIsBatch: true,
      dataForm: {
        title: ""
      }
    });
    return { ...useView(state), ...toRefs(state) };
  },
  methods: {
    editClassHour(id: string) {
      this.courseId = id;
      this.dictTypeListVisible = true;
    },
    editCourseFile(id: string) {
      this.courseId = id;
      this.courseFileVisible = true;
    },
    tuijianHandle(id: string) {
      ui.confirm("确认推荐", "确认推荐", {
        confirmButtonText: "确认",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        baseService.get("/fii/fiicourse/tuijian/" + id);
        this.getDataList();
      });
    }
  },
  watch: {}
});
</script>
